<template>
  <div>
    <!-- 入职 -->
    <div>
      
    </div>
    <!-- <el-row>
      <el-col :span="22">
        <div class="sec-title">职位管理</div>
      </el-col>
      <el-col :span="2">
        <div>
          <i class="el-icon-plus sec-blue"></i>
          <el-button @click="saveHandle" type="text">新增</el-button>
        </div>
      </el-col>
    </el-row> -->
    <!-- 筛选条件 -->
    <el-form
      :inline="true"
      :model="queryParams"
      class="demo-form-inline"
    >
      <el-form-item label="角色名称">
        <el-input
          v-model="queryParams.roleName"
          placeholder="角色名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="initSearchRoles"
        >查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :data="roles"
      height="590"
      @row-click="roleCallback"
    >
      <el-table-column
        prop="roleId"
        label="角色编号"
      >
      </el-table-column>
      <el-table-column
        prop="roleName"
        label="角色名称"
      >
      </el-table-column>
      <el-table-column
        prop="roleDesc"
        label="角色描述"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="pageData.total"
      @prev-click="preHandle"
      @next-click="nextHandle"
      @current-change="currentChangeHandle"
    >
    </el-pagination>
  </div>
</template>
<script>
import { queryRoles } from '@/api/system/system';
export default {
  data() {
    return {
      roles: [],
      queryParams: {
          roleName: '',
          current: 0,
          pageSize: 10
      },
      pageData: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  async mounted() {
    this.initSearchRoles()
  },
  computed: {
  },
  methods: {
    preHandle(current) {
      this.currentChangeHandle(current)
    },
    nextHandle(current) {
      this.currentChangeHandle(current)
    },
    currentChangeHandle(current) {
      this.pageData.current = current
      this.searchRoles()
    },
    initSearchRoles() {
      this.pageData.current = 1
      this.pageData.pageSize = 10
      this.searchRoles()
    },
    async searchRoles() {
      this.queryParams.current = this.pageData.current
      this.queryParams.pageSize = this.pageData.pageSize
      const {data: res} = await queryRoles(this.queryParams)
      if (res.code === 200) {
        this.roles = res.data.roles.records
        this.pageData.total = res.data.roles.total
      }
    },
    roleCallback(row) {
      this.$emit('selectRole', row)
    }
  },
};
</script>

<style lang="css" scoped>
.sec-blue {
  color: #409eff;
}
.sec-title {
  font-size: 18px;
  font-weight: 700;
}
</style>